import React from "react";
import { message, Space } from "antd";

import {
  AreaChartOutlined,
  TeamOutlined,
  UserOutlined,
} from "@ant-design/icons";
import "./home.css";
import {
  _getStuNumber,
  _getTchNumber,
  _getExpNumber,
} from "../../../../utils/user/index";
class AddArticle extends React.Component {
  state = {
    stu_num: 0,
    tch_num: 0,
    exp_num: 0,
    isLoading: false,
  };
  componentDidMount = () => {
    this.setState({ isLoading: true });

    _getStuNumber()
      .then((res) => {
        if (res.status === 200 && res.data.code === 0) {
          this.setState({ stu_num: res.data.data[0].count });
        }
      })
      .catch(() => {
        this.setState({ isLoading: false });
        message.error("服务器错误");
      });
    _getTchNumber()
      .then((res) => {
        if (res.status === 200 && res.data.code === 0) {
          this.setState({ tch_num: res.data.data[0].count });
        }
      })
      .catch(() => {
        this.setState({ isLoading: false });
        message.error("服务器错误");
      });
    _getExpNumber()
      .then((res) => {
        if (res.status === 200 && res.data.code === 0) {
          this.setState({ exp_num: res.data.data[0].count, isLoading: false });
        }
      })
      .catch(() => {
        this.setState({ isLoading: false });
        message.error("服务器错误");
      });
  };
  render() {
    return (
      <div>
        <div style={{ padding: 24, minHeight: 360 }}>
          <div className="home-container">
            <div
              className="home-top-item1"
              onClick={() => this.props.history.push("/admin/s")}
            >
              <div className="home-num">{this.state.stu_num}</div>
              <div className="home-title">
                <Space>
                  <TeamOutlined />
                  学生总数
                </Space>
              </div>
            </div>
            <div
              className="home-top-item2"
              onClick={() => this.props.history.push("/admin/t")}
            >
              <div className="home-num">{this.state.tch_num}</div>
              <div className="home-title">
                <Space>
                  <UserOutlined />
                  教师总数
                </Space>
              </div>
            </div>
            <div className="home-top-item3">
              <div className="home-num">{this.state.exp_num}</div>
              <div className="home-title">
                <Space>
                  <AreaChartOutlined />
                  实验总数
                </Space>
              </div>
            </div>
          </div>
        </div>
      </div>
    );
  }
}

export default AddArticle;
